package com.cxh.rmsq.ui.activity.self

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import android.view.KeyEvent
import androidx.core.view.isVisible
import com.cxh.rmsq.R
import com.cxh.rmsq.databinding.ActivityClueListBinding
import com.cxh.rmsq.databinding.ActivityUnderModeBinding
import com.cxh.rmsq.ui.activity.TitleBaseActivity
import io.rong.callkit.util.SPUtils

/**
 * 未成年模式
 */
class UnderModeActivity : TitleBaseActivity() {
    private lateinit var binding: ActivityUnderModeBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityUnderModeBinding.inflate(layoutInflater)
        setContentView(binding.root)
        titleBar.tvTitle.text = "未成年模式"

    }

    override fun onResume() {
        super.onResume()
        if (TextUtils.isEmpty(SPUtils.get(this, "UNDER_PWD", "").toString())) {
            binding.stvOpen.text = "开启未成年模式"
            titleBar.btnLeft.isVisible = true
        } else {
            binding.stvOpen.text = "关闭未成年模式"
            titleBar.btnLeft.isVisible = false
        }
        binding.stvOpen.setOnClickListener {
            startActivity(Intent(this, SetUnderPwdActivity::class.java))
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        return if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (TextUtils.isEmpty(SPUtils.get(this, "UNDER_PWD", "").toString())) {
                finish()
                false
            }else{
                true
            }
        } else {
            super.onKeyDown(keyCode, event)
        }
    }
}